package Frame.screen;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import FCRendering.ImageUtil;
import VWorldGameStudio.FCItem;
import VWorldGameStudio.FCPlayerInfo;
import VWorldGameStudio.FCTank;
import Function.FCMutilPlayCache;

import java.awt.*;

import static FCRendering.FCRMaster.*;
import static FCRendering.FCRMaster.fcv;

public class DefaultItemScreen extends IScreen {
    private Font font3;

    @Override
    public void dispatchPaintComponent(Graphics g, FCRMaster fcrMaster) {
        //背包物品背景
        g.drawImage(ImageUtil.getImage("gameplayerkna"), (int) ((fcrMaster.getWidth() - 654 * fcv.getProportion()) / 2),
                (int) (fcrMaster.getHeight() - 78 * fcv.getProportion()), (int) (654 * fcv.getProportion()), (int) (78 * fcv.getProportion()), this);// 玩家背包

        FCPlayerInfo fcPlayerInfo = FCMutilPlayCache.findPlayerByName(gameSave.HOST_UID, fcv.getShowWhosBagItem());
        if (fcPlayerInfo != null) {

            // 渲染背包物品
            for (int i = 0; i < 10; i++) {
                String itemidd = fcPlayerInfo.getKnapsackItemIDOfNum(i);
                if (itemidd != null && !itemidd.equals("null")) {
                    if (fcv.isMoveKnapsackItem() && !fcv.getShowWhosBagItem().equals(fcv.getKnapsackItemWho())) {
                        g.drawImage(itemLib.getItemOfID(itemidd).getPngPng(),
                                (int) ((583 + 64 * (i + 1)) * fcv.getProportion()), (int) (fcrMaster.getHeight() - 64 * fcv.getProportion()),
                                (int) (50 * fcv.getProportion()), (int) (50 * fcv.getProportion()), this);

                    } else {
                        if (fcv.getKnapsackItemType() == 1 && fcv.isMoveKnapsackItem() && fcv.getKnapsackItemNum() == i
                                && fcv.getShowWhosBagItem().equals(fcv.getKnapsackItemWho()))// 移动背包物品
                        {
                            //不用做什么
                        } else {
                            g.drawImage(itemLib.getItemOfID(itemidd).getPngPng(),
                                    (int) ((583 + 64 * (i + 1)) * fcv.getProportion()), (int) (fcrMaster.getHeight() - 64 * fcv.getProportion()),
                                    (int) (50 * fcv.getProportion()), (int) (50 * fcv.getProportion()), this);
                        }
                    }
                }
            }
            //渲染坦克中的道具物品
            if (fcPlayerInfo.getPlayertank1() != null && !fcPlayerInfo.getPlayertank1().equals("null")) {
                FCTank tank = tankLib.getTankOfID(fcPlayerInfo.getPlayertank1(), fcPlayerInfo.getPlayertankHostId());
                if (tank != null) {
                    g.drawImage(ImageUtil.getImage("gameplayerkna"), (int) ((fcrMaster.getWidth() - 654 * fcv.getProportion()) / 2),
                            (int) (fcrMaster.getHeight() - 156 * fcv.getProportion()), (int) (654 * fcv.getProportion()), (int) (78 * fcv.getProportion()), this);
                    for (int i = 0; i < 10; i++) {
                        String tItem = tank.getKnapsack()[i];
                        if (tItem != null && !tItem.equals("null")) {
                            if (fcv.isMoveKnapsackItem() && !fcv.getShowWhosBagItem().equals(fcv.getKnapsackItemWho())) {
                                g.drawImage(itemLib.getItemOfID(tItem).getPngPng(),
                                        (int) ((583 + 64 * (i + 1)) * fcv.getProportion()), (int) (fcrMaster.getHeight() - 143 * fcv.getProportion()),
                                        (int) (50 * fcv.getProportion()), (int) (50 * fcv.getProportion()), this);

                            } else {
                                if (fcv.getKnapsackItemType() == 2 && fcv.isMoveKnapsackItem() && fcv.getKnapsackItemNum() == i
                                        && fcv.getShowWhosBagItem().equals(fcv.getKnapsackItemWho()))// 移动背包物品
                                {

                                } else {
                                    g.drawImage(itemLib.getItemOfID(tItem).getPngPng(),
                                            (int) ((583 + 64 * (i + 1)) * fcv.getProportion()), (int) (fcrMaster.getHeight() - 143 * fcv.getProportion()),
                                            (int) (50 * fcv.getProportion()), (int) (50 * fcv.getProportion()), this);
                                }
                            }
                        }
                    }
                }
            }
            if (fcv.isMoveKnapsackItem()) {
                FCItem item = itemLib.getItemOfID(fcv.getKnapsackItemName());
                if(item != null)
                  g.drawImage(item.getPngPng(), (int) (fcv.getMouseX() - 25 * fcv.getProportion()),
                        (int) (fcv.getMouseY() - 25 * fcv.getProportion()), (int) (50 * fcv.getProportion()), (int) (50 * fcv.getProportion()),
                        this);
            }
        }

//        if (fcv.getBattleResultText().size() > 0) {
//            g.drawImage(ImageUtil.getImage("gamefightsayframe"), (int) (632 * fcv.getProportion()),
//                    (int) (888 * fcv.getProportion()), (int) (856 * fcv.getProportion()), (int) (192 * fcv.getProportion()), this);
//            g.setColor(Color.white);
//            g.setFont(font3);
//            int n = fcv.getBattleResultText().size();
//            if(n > 2){
//                g.drawString(fcv.getBattleResultText().get(n-3), (int) (652 * fcv.getProportion()),
//                        (int) (948 * fcv.getProportion()));
//                g.drawString(fcv.getBattleResultText().get(n-2), (int) (652 * fcv.getProportion()),
//                        (int) (988 * fcv.getProportion()));
//                g.drawString(fcv.getBattleResultText().get(n-1), (int) (652 * fcv.getProportion()),
//                        (int) (1028 * fcv.getProportion()));
//            }else if(n > 1){
//                g.drawString(fcv.getBattleResultText().get(n-2), (int) (652 * fcv.getProportion()),
//                        (int) (948 * fcv.getProportion()));
//                g.drawString(fcv.getBattleResultText().get(n-1), (int) (652 * fcv.getProportion()),
//                        (int) (988 * fcv.getProportion()));
//            }else {
//                g.drawString(fcv.getBattleResultText().get(n-1), (int) (652 * fcv.getProportion()),
//                        (int) (948 * fcv.getProportion()));
//            }
//        }

        String sayText = fcv.getBattleSayText().peek();
        if (sayText != null) {
            g.drawImage(ImageUtil.getImage("gamefightsayframe"), (int) (632 * fcv.getProportion()),
                    (int) (888 * fcv.getProportion()), (int) (856 * fcv.getProportion()), (int) (192 * fcv.getProportion()), this);

            g.setColor(Color.white);
            g.setFont(font3);
            g.drawString(sayText, (int) (682 * fcv.getProportion()),
                    (int) (948 * fcv.getProportion()));
        }

        if(fcv.getLookIntos().size() > 0){
            g.setColor(Color.white);
            g.setFont(font3);
            int showLen = Math.min(5, fcv.getLookIntos().size());
            g.drawImage(ImageUtil.getImage("gamefightsayframe"), (int) (632 * fcv.getProportion()),
                    (int) (888 * fcv.getProportion()), (int) (856 * fcv.getProportion()), (int) (192 * fcv.getProportion()), this);
            for(int i = 0;i< showLen; i++) {
                try {
                    String text = fcv.getLookIntos().get(i);
                    g.drawString(text, (int) (682 * fcv.getProportion()),
                            (int) ((i * 24 + 948) * fcv.getProportion()));
                }catch (Exception e){}
            }
        }
    }

    @Override
    public void setBounds() {
        font3 = new Font(FCRConstants.FONT_ELEGANT_BLACK, Font.BOLD, (int) (26 * fcv.getProportion()));
    }
}
